﻿using KwaiXiaoDian.Data;
using KwaiXiaoDian.Entity.DO;
using KwaiXiaoDian.Entity.VO.Product;
using KwaiXiaoDian.IDao;
using SSharing.Frameworks.NetCore.Common.Extends;
using SSharing.Frameworks.NetCore.Common.Results;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KwaiXiaoDian.Dao
{
    /// <summary>
    /// 商品出单达人排行榜dao
    /// </summary>
    public class ProductRankDao : BaseDao<TProductRank>, IProductRankDao
    {
        private readonly KwaiXiaoDianDbContext _kwaiXiaoDianDbContext;

        public ProductRankDao(KwaiXiaoDianDbContext kwaiXiaoDianDbContext) : base(kwaiXiaoDianDbContext)
        {
            _kwaiXiaoDianDbContext = kwaiXiaoDianDbContext;
        }

        /// <summary>
        /// 获取商品达人排行榜
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public IPagingResult<TProductRank> GetPagingRanks(GetPagingRanksRequest request)
        {
            IPagingResult<TProductRank> pagingResult = new PagingResult<TProductRank>();

            var query = _kwaiXiaoDianDbContext.TProductRank.Where(p => p.ProductId == request.ProductId);

            //默认按排名升序排序
            query = query.OrderBy(p => p.Rank);

            //分页
            return query.PagingWithNoLock(request.Page, request.Limit);
        }


    }
}
